/**
 * Project Name:sc-parent-web
 * File Name:BizController.java
 * Package Name:com.sc.controller
 * Date:2018年7月1日下午3:27:21
 * Copyright (c) 2018, bluemobi All Rights Reserved.
 */

package com.sc.controller;
/**
 * Description:   <br/>
 * Date:     2018年7月1日 下午3:27:21 <br/>
 * @author   pengchengwang
 * @version
 * @see
 */

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sc.pojo.DynmicSelect;
import com.sc.pojo.Facility;
import com.sc.pojo.House;
import com.sc.pojo.Items;
import com.sc.service.ItemsService;

@Controller
@RequestMapping(value = "/WHeadInfoController")
public class WHeadInfoController {
    @Autowired
    private ItemsService itemsService;

    // 首页的展示界面
    @RequestMapping(value = "/intoMainPage")
    public String intoMainPage(Map<String, Object> map) {
        // 查询项目信息
        List<Items> list = itemsService.selectItemsAllInfo();
        map.put("listItemsAllInfo", list);
        return "sc-mainpage";
    }

    // 查看当前id对应的项目下的房屋的类别介绍及周边
    @RequestMapping(value = "/selectItemsAllInfo")
    public String selectItemsAllInfo(String id, Map<String, Object> map) {

        /*
         * List<Facility> list =
         * itemsService.selectAllFiveInfo(Integer.parseInt(id));
         * map.put("listItemsAllInfo", list.get(0));
         */

        /* return "sc-profileinfo"; */
        // 获取项目的类型
        List<Facility> listFacility = itemsService.selectByIdRimAndFacility(Integer.parseInt(id));

        // 根据项目id获取项目的信息
        Items items = itemsService.selectByIdItemsInfo(Integer.parseInt(id));
        // 根据项目id获取所有的房子信息及类型
        List<House> listHouseInfo = itemsService.selectByIdHouseAllInfo(Integer.parseInt(id));
        System.out.println(listHouseInfo.size());
        boolean flag = true;
        for (int i = 0; i < listHouseInfo.size(); i++) {
            for (int j = i + 1; j <= listHouseInfo.size() - 1; j++) {
                if (listHouseInfo.get(i).getDid() == listHouseInfo.get(j).getDid()) {
                    listHouseInfo.remove(listHouseInfo.get(j));
                    if (flag && i != 0) {
                        i = i - 1;
                        flag = false;
                    }
                    j = j - 1;
                }
            }
            flag = true;
        }
        System.out.println(listHouseInfo);
        map.put("listHouseInfo", listHouseInfo);
        map.put("items", items);
        map.put("listFacility", listFacility);
        return "sc-profileinfo";

    }

    // 跳转到查询所有的项目的信息列表

    @RequestMapping(value = "/selectAllItemsInfo")
    public String selectAllItemsInfo(Map<String, Object> map) {
        // 查询项目信息
        List<Items> list = itemsService.selectItemsAllInfo();
        map.put("listItemsAllInfo", list);
        return "sc-profilelist";
    }

    @RequestMapping(value = "seachInfo")
    public String seachInfo() {
        return "sc-search";
    }

    // 动态查询
    @RequestMapping(value = "/dynmicSelectInfo")
    public String dynmicSelectInfo(DynmicSelect dSelect, Map<String, Object> map2) {
        System.out.println(dSelect.toString());
        HashMap<String, Object> map = new HashMap<String, Object>();
        if (dSelect.getIname() != null && dSelect.getIname().trim().length() != 0) {
            map.put("iname", "%" + dSelect.getIname().trim() + "%");
            // System.out.println("项目名" + dSelect.getIname());
        }
        if (dSelect.getDtype() != null && dSelect.getDtype().trim().length() != 0) {
            map.put("dtype", "%" + dSelect.getDtype().trim() + "%");
            // System.out.println("房屋类型" + dSelect.getDtype());
        }
        if (dSelect.getHarea() != null && dSelect.getHarea().trim().length() != 0) {
            if (dSelect.getHarea().equals("60")) {
                map.put("harea1", dSelect.getHarea().trim());
                // System.out.println("房屋面积1" + dSelect.getHarea());
            } else {
                String[] strings = dSelect.getHarea().split("-");
                map.put("harea1", strings[0]);
                map.put("harea2", strings[1]);
                // System.out.println("房屋面积1" + strings[0]);
                // System.out.println("房屋面积2" + strings[1]);
            }

        }
        if (dSelect.getEprice() != null && dSelect.getEprice().trim().length() != 0) {
            if (dSelect.getEprice().equals("10000")) {
                map.put("eprice1", dSelect.getEprice().trim());
                // System.out.println("房屋价格1" + dSelect.getEprice());
            } else {
                String[] strings = dSelect.getEprice().split("-");
                map.put("eprice1", strings[0]);
                map.put("eprice2", strings[1]);
                // System.out.println("房屋价格1" + strings[0]);
                // System.out.println("房屋价格2" + strings[1]);
            }
        }
        if (dSelect.getHfloor() != null && dSelect.getHfloor().trim().length() != 0) {
            if (dSelect.getHfloor().equals("7")) {
                map.put("hfloor1", dSelect.getHfloor().trim());
                // System.out.println("房屋楼层1" + dSelect.getHfloor());
            } else {
                String[] strings = dSelect.getHfloor().split("-");
                map.put("hfloor1", strings[0]);
                map.put("hfloor2", strings[1]);
                // System.out.println("房屋楼层1" + strings[0]);
                // System.out.println("房屋楼层2" + strings[1]);
            }
        }
        if (dSelect.getRfacility() != null && dSelect.getRfacility().trim().length() != 0) {

            map.put("rfacility", dSelect.getRfacility().trim());
            // System.out.println("项目周边设施名称" + dSelect.getRfacility());
        }
        if (dSelect.getIaddress() != null && dSelect.getIaddress().trim().length() != 0) {
            String[] strings = dSelect.getIaddress().split(" ");
            String iaddress = "";
            for (String string : strings) {
                iaddress = iaddress + string;
            }
            map.put("iaddress", "%" + iaddress.trim() + "%");
            // System.out.println("项目地址" + iaddress);
            /* map.put("getRfacility", dSelect.getRfacility()); */

        }
        List<Facility> list = itemsService.selectDymicAll(map);
        /*
         * System.out.println(list.size()); for (Facility facility : list) {
         * System.out.println("周边的具体设施" + facility.getFname()); Rim rim =
         * facility.getRim(); System.out.println("周边的大概设施" +
         * rim.getRfacility()); Set<Items> set = rim.getItems(); for (Items
         * items : set) { System.out.println("项目名称" + items.getIname());
         * Set<House> set2 = items.getSet(); for (House house : set2) {
         * System.out.println("房子的介绍" + house.getHdesc()); Designtype designtype
         * = house.getDesigntype(); System.out.println("房子的类型" +
         * designtype.getDtype()); }
         * 
         * } System.out.println("---------------------------"); }
         */
        map2.put("listFacilityInfo", list);
        return "sc-searchpage";
    }

    @RequestMapping(value = "/intoPicInfo")
    public String intoPicInfo() {
        return "sc-picinfo";

    }

    @RequestMapping(value = "/show4")
    @ResponseBody
    public List<HashMap<String, Object>> show4() {
        List<HashMap<String, Object>> list = itemsService.selectByiIdHouseAndType(1);
        return list;
    }

    /*
     * public static void main(String[] args) { List<Integer> list = new
     * ArrayList<Integer>(); list.add(3); list.add(1); list.add(2); list.add(3);
     * list.add(4); list.add(2); list.add(3); list.add(1); list.add(2);
     * list.add(3); list.add(4); list.add(2); list.add(3); for (int i = 0; i <
     * list.size(); i++) { for (int j = i + 1; j < list.size(); j++) { if
     * (list.get(i) == list.get(j)) { list.remove(j); j--; } } }
     * System.out.println(list); }
     */
}
